package com.wongsir.tiny_ioc.step3;

import org.junit.Test;

import com.wongsir.step3.tiny_ioc.BeanDefinition;
import com.wongsir.step3.tiny_ioc.PropertyValue;
import com.wongsir.step3.tiny_ioc.PropertyValues;
import com.wongsir.step3.tiny_ioc.factory.AutowireCapableBeanFactory;
import com.wongsir.step3.tiny_ioc.factory.BeanFactory;

/**
 * step3:
 * @author wongsir
 * @date 2018年9月13日
 */
public class BeanFactoryTest3 {
	
	@Test
	public void test() throws Exception {
		//1、初始化BeanFactory
		BeanFactory beanFactory = new AutowireCapableBeanFactory();
		
		//2、bean定义
		BeanDefinition beanDefinition = new BeanDefinition();
		beanDefinition.setBeanClassName("com.wongsir.tiny_ioc.step3.HelloWorldService");
		
		//3、属性设置
		PropertyValues propertyValues = new PropertyValues();
		propertyValues.addPropertyValue(new PropertyValue("text","hello world"));
		beanDefinition.setPropertyValues(propertyValues);
		
		//4、生成bean(放入bean工厂等待取用)
		beanFactory.registerBeanDefinition("helloWorldService", beanDefinition);
		
		//5、获取bean
		HelloWorldService helloWorldService = (HelloWorldService) beanFactory.getBean("helloWorldService");
		helloWorldService.helloWorld();
	}
}
